package storm.topology;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.testing.TestGlobalCount;
import org.apache.storm.testing.TestWordCounter;
import org.apache.storm.testing.TestWordSpout;
import org.apache.storm.topology.TopologyBuilder;
import org.apache.storm.tuple.Fields;

/**
 * Created by luoqifei on 2016/10/1.
 */
public class Topology {
//    command:    mvn assembly:assembly
//    storm jar path/to/allmycode.jar org.me.MyTopology arg1 arg2 arg3
//    kill topology command: storm kill topologyName

    public static void main(String args[]){
       //commit topology by local model
        Config config = new Config();
        config.setMaxTaskParallelism(3);
        config.setMaxSpoutPending(100);
        LocalCluster cluster = new LocalCluster();
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", new TestWordSpout(true), 5);
        builder.setSpout("2", new TestWordSpout(true), 3);
        builder.setBolt("3", new TestWordCounter(), 3)
                .fieldsGrouping("1", new Fields("word"))
                .fieldsGrouping("2", new Fields("word"));
        builder.setBolt("4", new TestGlobalCount())
                .globalGrouping("1");
//        Map conf = new HashMap();
//        conf.put(Config.TOPOLOGY_WORKERS, 4);

        cluster.submitTopology("mytopology", config, builder.createTopology());
        System.out.println("good boy");
    }
}
